package com.book.system.controller;

import com.book.common.annotation.ControllerEndpoint;
import com.book.common.annotation.Log;
import com.book.common.controller.BaseController;
import com.book.common.entity.FebsConstant;
import com.book.common.entity.FebsResponse;
import com.book.common.entity.QueryRequest;
import com.book.common.utils.FebsUtil;
import com.book.system.entity.LoginLog;
import com.book.system.service.LoginLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @Author: 黄海峰
 * @Description:  20155933
 */

@Controller
public class LoginLogController extends BaseController {
    @Autowired
    LoginLogService loginLogService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "user/loginLog")
    public String loginLogIndex() {
        return FebsUtil.view("system/user/loginLog");
    }

    @GetMapping("loginLog")
    @ResponseBody
    @RequiresPermissions("loginLog:view")
    public FebsResponse loginLogList(LoginLog loginLog) {
        return new FebsResponse().success().data(this.loginLogService.findAllLogs(loginLog));
    }

    @Log("访问登录日志")
    @GetMapping("loginLog/list")
    @ResponseBody
    @RequiresPermissions("loginLog:view")
    public FebsResponse loginLogIPage(QueryRequest request, LoginLog loginLog) {
        Map<String, Object> dataTable = getDataTable(this.loginLogService.getLogByPage(request, loginLog));
        return new FebsResponse().success().data(dataTable);
    }

    @Log("登录日志-删除")
    @PostMapping("loginLog/delete/{ids}")
    @ResponseBody
    @RequiresPermissions("loginLog:delete")
    @ControllerEndpoint(operation = "删除日志信息成功", exceptionMessage = "删除日志信息失败")
    public FebsResponse loginLogdelete(@PathVariable String ids) {
        String[] attr = ids.split(",");
        this.loginLogService.deleteLogs(attr);
        return new FebsResponse().success();
    }
}
